package com.ynny.chapter05.service;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ynny.chapter05.entity.User;
import com.ynny.chapter05.mapper.UserMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;

@Service
public class UserServiceImpl
        extends ServiceImpl<UserMapper , User>
        implements UserService{

    @Resource
    UserMapper userMapper;

    @Override
    public PageInfo<User> pageInfo(int pageNum, int pageSize) {

        //开启分页

        PageHelper.startPage(pageNum,pageSize);

        //查询数据

        List<User> list = list();


        PageInfo<User> pageInfo = new PageInfo<>(list);

        return pageInfo;


    }

    @Override
    public PageInfo<User> pageInfoByUser(int pageNum, int pageSize) {

        PageHelper.startPage(pageNum , pageSize);

        List<User> users = baseMapper.selectAllUserAndAddress();

        PageInfo<User> userPageInfo = new PageInfo<>(users);

        return userPageInfo;


    }
}
